class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int counter[256]={0};
        int n=s.size(), biggerThanOne=0, j=0, ans=0;
        for (int i=0;i<n;i++){
            counter[s[i]]++;
            if (counter[s[i]]>1) biggerThanOne++;
            while (biggerThanOne>0){
                if (counter[s[j]]>1) biggerThanOne--;
                counter[s[j]]--;
                ++j;
            }
            if (ans<i-j+1) ans=i-j+1;
        }
        return ans;
    }
};
